package com.cserver.pro.service.impl;


import com.cserver.pro.dao.SysJobLogDao;
import com.cserver.pro.entity.SysJobLog;
import com.cserver.pro.service.SysJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 定时任务调度日志表(SysJobLog)表服务实现类
 *
 * @author makejava
 * @since 2020-02-18 21:39:31
 */
@Service("sysJobLogService")
public class SysJobLogServiceImpl implements SysJobLogService {

    @Autowired
    private SysJobLogDao sysJobLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param jobLogId 主键
     * @return 实例对象
     */
    @Override
    public SysJobLog queryById(Long jobLogId) {
        return this.sysJobLogDao.queryById(jobLogId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<SysJobLog> queryAllByLimit(int offset, int limit) {
        return this.sysJobLogDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param sysJobLog 实例对象
     * @return 实例对象
     */
//    @Transactional(noRollbackFor = RuntimeException.class)
    @Transactional
    @Override
    public SysJobLog insert(SysJobLog sysJobLog) {


//        try {
            this.sysJobLogDao.insert(sysJobLog);
//            Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
//            int result = 10 / 0;
            this.sysJobLogDao.insert(sysJobLog);
//            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
//        } catch (Exception e) {
//            c.currentTransactionStatus().setRollbackOnly();
//            e.printStackTrace();
//        }

        return sysJobLog;
    }

    /**
     * 修改数据
     *
     * @param sysJobLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysJobLog update(SysJobLog sysJobLog) {
        this.sysJobLogDao.update(sysJobLog);
        return this.queryById(sysJobLog.getJobLogId());
    }

    /**
     * 通过主键删除数据
     *
     * @param jobLogId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long jobLogId) {
        return this.sysJobLogDao.deleteById(jobLogId) > 0;
    }
}